home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / imap-3.0 / MailManager / ReplyWindow.m < prev    next >
Encoding:
Text File  |  1993-04-22  |  5.5 KB  |  155 lines

  1. /*
  2.  * Program:    Distributed Electronic Mail Manager (ReplyWindow object)
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    27 June 1989
  13.  * Last Edited:    22 April 1993
  14.  *
  15.  * Copyright 1993 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. #import "MailManager.h"
  38.  
  39. @implementation ReplyWindow
  40.  
  41. // Create a new ReplyWindow
  42.  
  43. + new:(MAILHANDLE *) h lelt:(LONGCACHE *) e text:(char *) text all:(BOOL) all
  44. {
  45.   char tmp[16*TMPLEN],frm[TMPLEN],c,*src,*dst,*d;
  46.   int i;
  47.   ENVELOPE *msg;
  48.   self = [super new];        // open a SendWindow, set as window's delegate
  49.   [[self window] setDelegate:self];
  50.   handle = h;            // note handle for later
  51.                 // note cache element for later and lock
  52.   if (!++((lelt = e)->elt.lockcount)) fatal ("Elt lock count overflow");
  53.                 // copy reply-to
  54.   (msg = [self msg])->to = copy_adr (e->env->reply_to,NIL);
  55.   if (all) {            // copy to/cc lists if "reply all"?
  56.     if (msg->to) msg->cc = copy_adr (e->env->cc,copy_adr (e->env->to,msg->cc));
  57.     else msg->to = copy_adr (e->env->cc,copy_adr (e->env->to,NIL));
  58.     msg->bcc = copy_adr (e->env->bcc,msg->bcc);
  59.   }
  60.   if (e->env->subject) {    // use subject in reply if present
  61.     strncpy (tmp,e->env->subject,3);
  62.     tmp[3] ='\0';        // tie off copy of first 3 chars
  63.     ucase (tmp);        // make the whole thing uppercase
  64.                 // a "re:" already there?
  65.     if (strcmp (tmp,"RE:")) sprintf (tmp,"re: %s",e->env->subject);
  66.     else sprintf (tmp,"%s",e->env->subject);
  67.   }
  68.   else sprintf (tmp,"(response to message of %s)",e->env->date);
  69.   msg->subject = cpystr (tmp);    // copy desired subject
  70.                 // calculate simple from
  71.   if (!e->env->from) strcpy (frm,"(unknown)");
  72.   else if (e->env->from->personal) strcpy (frm,e->env->from->personal);
  73.   else sprintf (frm,"%s@%s",e->env->from->mailbox,e->env->from->host);
  74.                 // in-reply-to is our message-id if exists
  75.   if (e->env->message_id) sprintf (tmp,"%s",e->env->message_id);
  76.   else sprintf (tmp,"Message of %s from %s",e->env->date,frm);
  77.   msg->in_reply_to = cpystr (tmp);
  78.  
  79.   sprintf (tmp,"On %s, %s wrote:\n\n> Subject: %s\n",
  80.        e->env->date,frm,e->env->subject ? e->env->subject : "(none)");
  81.   d = tmp + strlen (tmp);
  82.   write_address (&d,"> To",e->env->to);
  83.   write_address (&d,"> cc",e->env->cc);
  84.   strcat (d,">\n> ");        // trailing junk
  85.                 // get size of header + text
  86.   i = strlen (src = text) + strlen (tmp);
  87.                 // plus space for leading widgits in string
  88.   while (*src) if (*src++ == '\n') i += 2;
  89.   strcpy (d = fs_get (i+1),tmp);// start with header
  90.   dst = d + strlen (d);        // set destination at end of header
  91.   src = text;            // set up for copy
  92.   while (c = *src++) {        // copy string, inserting brokets at each line
  93.     if (c != '\r') *dst++ = c;    // first copy the character (nuke CR if seen)
  94.     if ((c == '\n') && *src) {    // if newline and not end
  95.       *dst++ = '>';        // insert widgit + space if not blank line
  96.       if (*src != '\n') *dst++ = ' ';
  97.     }
  98.   }
  99.                 // back over blank lines
  100.   while ((dst[-1] == '\n') && (dst[-2] == '>') && (dst[-3] == '\n')) dst -= 2;
  101.                 // ensure ending with newline
  102.   if (dst[-1] != '\n') *dst++ = '\n';
  103.   *dst++ = '\0';        // tie off string
  104.   [NXApp setPasteboard:d];    // write reply message to pasteboard
  105.   fs_give ((void **) &d);    // return the space
  106.   return [self updateEnvelopeView];
  107. }
  108.  
  109. // "Attach" on bottom of read window
  110.  
  111. - attachWindow:w
  112. {
  113.   NXRect frame;
  114.   NXPoint pt;
  115.   [window getFrame:&frame];    // get our dimensions
  116.   pt.x = 0;            // get window's bottom left corner
  117.   pt.y = 0;
  118.   [w convertBaseToScreen:&pt];    // get it in screen coordinates
  119.                 // move our top left to that place
  120.   [window moveTopLeftTo:pt.x :max (pt.y,NX_HEIGHT (&frame))];
  121.   return self;
  122. }
  123.  
  124.  
  125. // Reply has been sent
  126.  
  127. - exit:sender
  128. {
  129.   char tmp[TMPLEN];
  130.   MAILSTREAM *stream = handle ? mail_stream (handle) : NIL;
  131.   if (stream && lelt->elt.msgno) {
  132.                 // mark message as answered
  133.     sprintf (tmp,"%lu",lelt->elt.msgno);
  134.     mail_setflag (stream,tmp,"\\Answered");
  135.                 // update status in main window
  136.     [(getstreamprop (stream))->window updateTitle];
  137.   }
  138.   [super exit:self];        // do the superior's actions
  139.   return self;
  140. }
  141.  
  142.  
  143. // Window is closing
  144.  
  145. - windowWillClose:sender
  146. {
  147.   mail_free_lelt (&lelt);    // flush the cache element
  148.   mail_free_handle (&handle);    // flush the MAIL stream handle
  149.                 // do the superior's actions
  150.   return [super windowWillClose:sender];
  151. }
  152.  
  153.  
  154. @end
  155.